package com.gwd.task.repository;

import com.gwd.task.entity.UserEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.Optional;

/**
 * @author zhiyongming
 * @date 2020/11/9 9:53
 */
@Repository
public interface UserRepository extends JpaRepository<UserEntity, Long>, JpaSpecificationExecutor<UserEntity> {
    @Query(value = "select u from UserEntity u where u.userName=?1")
    Optional<UserEntity> getByUserName(String userName);

    @Modifying
    @Transactional
    @Query(value = "update UserEntity u set u.password = ?1 where u.userId=?2")
    void resetPass(String pass, Long userId);
}
